<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const person = {
        name: "jack",
        age: 21,
        language: ['java', 'c++', 'python']
    };

    console.log(Object.keys(person)); // ["name", "age", "language"]
    console.log(Object.values(person));// ["jack", 21, Array(3)]
    console.log(Object.entries(person));// [Array(2), Array(2), Array(2)]

    const target = {a: 1};
    const source1 = {b: 2};
    const source2 = {c: 3};
    Object.assign(target, source1, source2);
    console.log(target);
</script>
<script>
    //声明式对象简写
    const age = 18;
    const name = "赵五";
    const person2 = {age, name};
    console.log(person2);

    let person3 = {
        name: "jack",
        eat: function (food) {
            console.log(this.name + "在吃" + food);
        },
        eat2: food => console.log(person3.name + "在吃" + food),
        eat3(food) {
            console.log(this.name + "在吃" + food);
        }
    };
    person3.eat("香蕉");
    person3.eat2("西瓜"); // 常用
    person3.eat3("火龙果"); // 常用
</script>

<script>
    console.log("=================================");
    // 对象扩展运算符
    let p1 = {name: "Amy", age: 19};
    let someone = {...p1};// 合并1个对象
    console.log(someone);

    // 合并对象
    let subject1 = {subject: "数学"};
    let name1 = {name: "王二"};
    let age1 = {age: 20};
    let person_new = {subject1, ...name1, ...age1};// 合并多个对象
    console.log(person_new);
</script>
</body>
</html>